import prompt from '@system.prompt';
import config from '../config/config.js'

export function goToAbility(abilityName, dataInfo, flag) {
    var action = {};
    action.bundleName = config.BUNDLE_NAME;
    action.flag = flag;
    action.abilityName = abilityName
    action.data = dataInfo;
    //@ts-ignore
    FeatureAbility.startAbility(action);
}

//字节数组转十六进制字符串，对负值填坑
export function Bytes2HexString(arrBytes) {
    var str = '';
    for (var i = 0; i < arrBytes.length; i++) {
        var tmp;
        var num = arrBytes[i];
        if (num < 0) {
            tmp = (255 + num + 1).toString(16);
        } else {
            tmp = num.toString(16);
        }
        if (tmp.length == 1) {
            tmp = '0' + tmp;
        }
        str += tmp;
    }
    return str;
}

export function showToast(msg) {
    prompt.showToast({
        message: msg,
        duration: config.toast_duration
    })
}

export function isEmpty(obj) {
    if (typeof obj === 'undefined' || obj == null || obj === '') {
        return true;
    } else {
        return false;
    }
}